@extends('admin.layout')

@section('title', '编辑分类')

@section('body')
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">编辑分类</div>
                    <div class="layui-card-body layui-row">
                        <form class="layui-form layui-col-lg9">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">分类ID</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="id" value="{{ $id }}" readonly class="layui-input layui-disabled">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">分类名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="name" value="{{ $name }}" required lay-verify="required"
                                               placeholder="请输入分类名称" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">META关键词</label>
                                <div class="layui-input-block">
                                    <input type="text" name="keywords" value="{{ $keywords }}" required lay-verify="required"
                                           placeholder="多个关键词用英文逗号分隔" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">META描述</label>
                                <div class="layui-input-block">
                                    <textarea name="description" required lay-verify="required" placeholder="输入分类描述便于SEO索引"
                                              class="layui-textarea">{{ $description }}</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">排序值</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="list_order" value="{{ $list_order }}" required
                                               lay-verify="required|number" autocomplete="off" class="layui-input">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">越小越靠前</div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">URL别名</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="alias" value="{{ $alias }}" required lay-verify="required"
                                               autocomplete="off" class="layui-input">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">只能包含字母、数字和连字符（-）</div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">显示为菜单</label>
                                    <div class="layui-input-inline">
                                        <input type="checkbox" value="1" name="show_menu" @if ($show_menu) checked @endif lay-skin="switch"
                                               lay-text="ON|OFF">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="layui-btn" lay-submit="">提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use(['layer', 'form'], function () {
            var $ = layui.$;
            var layer = layui.layer;
            var form = layui.form;

            form.on('submit', function (obj) {
                $.post('/admin/category/edit', obj.field, function (res) {
                    if (res.code === 0) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            location.href = '/admin/category';
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                }, 'json');
                return false;
            });
        });
    </script>
@endsection
